﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla.OpenExpressApp;
using OpenExpressApp.Library.Audit;
using OpenExpressApp.MetaAttribute;
using OpenExpressApp.MetaModel;
using OpenExpressApp.Module.Library;
using OpenExpressApp.Types;
using OpenExpressApp.WPF.Command;
using Csla;
using System.Windows;

namespace OpenExpressApp.Module.WPF.Command.Audit
{
    /// <summary>
    /// 清空日志
    /// </summary>
    [Command(CommandNames.ClearAuditLogCommand, TargetObjectType = typeof(AuditItem), ImageName = "Cleanup.bmp", Label = "清空日志", ToolbarType = ToolbarType.Main)]
    public class ClearAuditLogCommand : WPFViewCommand
    {
        public override bool CanExecute(ObjectView view)
        {
            var list = view.Data as IList;
            return list != null && list.Count > 0;
        }
        public override void Execute(ObjectView view)
        {
            var result = MessageBox.Show("确定清空所有日志？", "请确认", MessageBoxButton.YesNo);
            if (result != MessageBoxResult.Yes) return;

            //清空
            DataPortal.Execute(new ClearLogCommand());

            //刷新数据
            var refresh = new RefreshCommand();
            refresh.Execute(view as ListObjectView);
        }
    }
}
